﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class 住户投诉管理 : Form
    {
        private static string _strConnstring = ConfigurationManager.AppSettings["sqlconn1"];

        public 住户投诉管理()
        {
            InitializeComponent();
        }



        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if (t_id.Text == "" || user.Text == "" || user_n.Text == "" || p_name.Text == "" || t_date.Text == "" || m_name.Text == "" || c_date.Text == "" || c_what.Text == "")
            {
                MessageBox.Show("全部填写，不能有为空的！!");

            }

            else
            {
                string ls_sql = "", ls_code, ls_name, ls_pwd, ls_npwd, ls_cd, ls_cd2, ls_cd3, ls_cd4;
                ls_code = t_id.Text.Trim();
                ls_name = user.Text.Trim();
                ls_pwd = user_n.Text.Trim();
                ls_npwd = p_name.Text.Trim();
                ls_cd = t_date.Text.Trim();
                ls_cd2 = m_name.Text.Trim();
                ls_cd3 = c_date.Text.Trim();
                ls_cd4 = c_what.Text.Trim();
                ls_sql = "insert into 投诉表 values('" + ls_code + "','" + ls_name + "','" + ls_pwd + "','" + ls_npwd + "','" + ls_cd + "','" + ls_cd2 + "','" + ls_cd3 + "','" + ls_cd4 + "');";


                SqlConnection myconn = new SqlConnection(_strConnstring);
                myconn.Open();
                SqlCommand mycommand = new SqlCommand(ls_sql, myconn);
                MessageBox.Show("添加成功！");
                mycommand.ExecuteNonQuery();
                myconn.Close();
            }

        }
        DataSet dsstudent = new DataSet();

        SqlDataAdapter dastudent = new SqlDataAdapter("select * from 投诉表", _strConnstring);
        SqlCommandBuilder cmdbuilder = new SqlCommandBuilder();
        public void display()
        {
            string ls_sql = "";
            string str_connstring;
            ls_sql = "select * from 投诉表 ";
            str_connstring = ConfigurationManager.AppSettings["sqlconn1"];

            SqlConnection myconn = new SqlConnection();
            myconn.ConnectionString = str_connstring;
            myconn.Open();
            SqlCommand mycommand = new SqlCommand(ls_sql, myconn);

            dastudent.Fill(dsstudent, "投诉表");
            dataGridView1.DataSource = dsstudent;
            dataGridView1.DataMember = "投诉表";

            mycommand.ExecuteNonQuery();
            myconn.Close();

        }

        private void 住户投诉管理_Load(object sender, EventArgs e)
        {
            MessageBox.Show("信息填写完整！");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            display();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            MessageBox.Show("根据投诉编号删除！");
            if (t_id.Text == "")
            {
                MessageBox.Show("投诉编号不能为空！");
            }
            else
            {


                string ls_sql = "";

                ls_sql = "delete from 投诉表 where 投诉编号 =t_id.text ";
                string str_connstring;
                str_connstring = ConfigurationManager.AppSettings["sqlconn1"];

                SqlConnection myconn = new SqlConnection();
                myconn.ConnectionString = str_connstring;
                myconn.Open();
                SqlCommand mycommand = new SqlCommand(ls_sql, myconn);
                MessageBox.Show("删除成功！");
                mycommand.ExecuteNonQuery();
                myconn.Close();
            }
        }


    }
}